home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / 4th86_v4.zip / TUTORIAL.TXT < prev    next >
Text File  |  1994-01-25  |  10KB  |  364 lines

  1.  
  2. splitscreen
  3.  
  4. ~
  5. 12
  6. splitscreen
  7. w1
  8. logo
  9. w2init
  10. w1
  11.   Welcome to 4th_86 implementation of the FORTH language.
  12.  
  13.  It is recommended that you print out and read the file INTRO.4TH as this 
  14.  will explain the concept of FORTH as an operating environment. However -- 
  15.  if you prefer the "learn by doing" approach -- carry on with this tutorial.
  16.  
  17.  Use keys 4 F2 N and 4 F1 N to page forward and back. At the last  page F2 
  18.  will cycle you back to the beginning page. F1 action ceases at  page 1.
  19.  
  20.              To leave 4th_86 and return to DOS type   4 BYE  N  
  21. $
  22.  
  23. ~
  24. w1init
  25. w2
  26.  The blue window is used for tutorial text. The Brown window is for you to 
  27.  enter commands and view results. 
  28.  
  29.  The power of 4th_86 lies in the "integrated development environment" FORTH 
  30.  as a language permits. Do not be discouraged initially by the "strange" 
  31.  symbols used -- or the "reverse" method of inputting variables and 
  32.  parameters. You will soon adapt to this as easily as you could to i++ and 
  33.  ++i or the perverse niceties of the semicolon in the C language -- or to 
  34.  the complex printf style formatting commands in Pascal; Fortran; or C. 
  35.  
  36. w2init
  37. w1
  38.  Try typing each of the following commands as you would if you were in MsDos
  39.  
  40.  **NOTE**  although commands are shown in upper case ( capital ) letters you
  41.   can type them in either upper or lower case. 4th_86 is not case sensitive.
  42.  
  43.       4  DIR  N   4  DIR \*.SYS  N    4  5 SECDELAY  N   4  TM   N  
  44.  
  45.  If you get in trouble -- use keys   4  F2 N or  4  F1 N to get  back to 
  46.  the tutorial and try again
  47. w1
  48. $
  49.  
  50. ~
  51. w1init
  52. 13
  53. w2
  54.  
  55.  Now let's try two more forth WORDS which will give you some background 
  56.  details -- but will temporarily erase the colored windows.
  57.  
  58.  Do not panic when all the tutorial instructions disappear!! You can easily 
  59.  get them back by using keys   4 F1       4 F2    -- or if that doesn't 
  60.  work, by typing   4  HELP     
  61.  
  62. w2init
  63. w1
  64.  So let's try it --- type  each of the following commands -- again just as 
  65.  you would if you were in MsDos
  66.  
  67.                 4  INFO   N                 4  INTRO  N     
  68.  
  69. w1
  70. $
  71. ~
  72. w2
  73. 2
  74.  Here is part of the the  4 STATUS   display
  75. w1
  76. status
  77. $
  78.  
  79. ~
  80. splitscreen
  81. w1init
  82. w2
  83.  
  84.  When you are using 4th_86 seriously as a programming tool -- you will not
  85.  usually be working in a colored window -- or half screen environment -- 
  86.  though you can if you so choose.
  87.  
  88.  In this exercise; once again all the tutorial text will disappear -- but 
  89.  this time  4 F1     4 F2    will not function. Only  4  HELP     
  90.  will return you to the tutorial text.
  91.  
  92. w2init
  93. w1
  94.  Write down the following commands to try once you exit windowed mode 
  95.  
  96.          4  DIR   N   4  STATUS  N   4 DDICT  N  4  FILES  N 
  97.  
  98.          4  DD GOTOXY   N   4  DD SECDELAY  N    
  99.  
  100.  Then type  4 FULLSCREEN  N to leave tutorial mode. 
  101.               Remember -- enter  4 HELP  N to return
  102. $
  103.  
  104. ~
  105. w1init
  106. 10
  107. w2
  108.  
  109.  4th_86 also allows you to use your own favorite DOS editor with a 
  110.  considerable degree of automation. You will need to configure the file 
  111.  EDITR.BAT to make this work - so let's leave that till you've read 
  112.  INTRO.4TH.
  113.  
  114.  FORTH is both an INTERPRETER and a COMPILER. It's much much more than 
  115.  BASIC is -- but let's use the concepts of BASIC and C as a starting 
  116.  point.
  117.  
  118. w1
  119.  
  120.    C version                Basic version
  121.    ---------                -------------
  122.   main(void)                10 for i = 1 to 10
  123.  {                    20 print i
  124.  int i;                    30 next
  125.     for (i=1; i<=10; i++ )
  126.     printf ("%d \n", i) ;        Forth version
  127.  }                    -------------
  128.                 : test1 10 0 do i . crlf loop ;
  129.  
  130. ~
  131. w1init
  132. 9
  133. w2
  134.  
  135.    C version                Basic version
  136.    ---------                -------------
  137.   main(void)                10 for i = 1 to 10
  138.  {                    20 print i
  139.  int i;                    30 next
  140.     for (i=1; i<=10; i++ )
  141.     printf ("%d \n", i) ;        Forth version
  142.  }                    -------------
  143.                 : test1 10 0 do i . crlf loop ;
  144. w1
  145.  
  146.  The C version has to be compiled and linked with a library to form an EXE
  147.  file before the program can be executed. The file can be named TEST1.EXE.
  148.  
  149.  The BASIC version can be run in INTERPRETER mode by typing the command RUN.
  150.  It can be saved as a file TEST1.BAS -- but this is not an executable file.
  151.  If a COMPILER rather than an INTERPRETER is used -- an EXE file can be 
  152.  created -- but BASIC interpreters and compilers are separate utilities.
  153.  
  154.  The FORTH version is COMPILED **as it is being written**. It has a name
  155.  TEST1 and can be immediately executed by typing TEST1. It can be saved 
  156.  either as an executable file TEST1.COM -- or source TEST1.4TH
  157. $
  158. ~
  159. split
  160. w2
  161. 9
  162.  
  163.   You could now type in the following four FORTH definitions
  164.  
  165.   4: test1 5 0 do i . crlf loop ;    4: test2 15 0 do i . tab  3 +loop ; 
  166.  
  167.    4: test3 10 0 do i . 2 spcs  loop ;     4: test4 20 5 do i . loop ; 
  168.  
  169.  However we have done it for you in a file called EXAMPLE1.4TH
  170.  so all you need do is type    4 FLOAD EXAMPLE1.4TH   
  171.  and then execute each word in turn by typing   4TEST1    4TEST2  etc
  172. $
  173.  
  174. ~
  175. split
  176. w1
  177. 23
  178.  
  179.  Note that definitions can continue over several lines
  180.  : test1
  181.     10 0
  182.        do 
  183.          i . crlf
  184.        loop
  185.   ;
  186.  
  187.  So that once you have entered a COLON sign -- 4th_86 will attempt to compile 
  188.  every statement you make -- up to the point at which it detects a SEMICOLON
  189.  
  190.  This causes few problems if you forget the semicolon -- because 4th_86 will
  191.  rapidly be given some text it doesn't recognise -- at which point it will
  192.  give an error message.
  193.  
  194. w1
  195. $
  196. ~
  197. split
  198. w1
  199. 23
  200.  
  201.  The same applies to comment delimiters -- a CR does NOT end a comment. This
  202.  can cause mysterious hangups as text you thought was being entered as a 
  203.  definition is being treated as an ongoing comment.
  204.  
  205.   : test5 20 0 do i . loop ;
  206.   
  207.   ( the above was test 5
  208.  
  209.     : test6 15 0 do i . 3 +loop ;
  210.  
  211.     ( that was test 6 )
  212.  
  213.    test5 has been entered as a definition. test6 however -- and any more
  214.  text that is typed in -- is ignored by 4th_86 as a comment; because the 
  215.  right hand ) delimiter after " was test 5 " has been missed out.
  216.  
  217.   You must take care to ensure brackets match -- as do colons and 
  218.   semicolons. If 4th_86 appears to have gone to sleep -- it is most likely
  219.   due to an unclosed comment string.
  220. w1
  221. $
  222. ~
  223. w1init
  224. 10
  225. w2
  226.  
  227.  The same care must be taken to match double-quote marks  "  in strings
  228.  
  229.   Load the file EXAMPLE2 by typing  4 FLOAD EXAMPLE2.4TH   
  230.  
  231.    Once you have loaded the file try out the words 
  232.      4  HEADER      4  FOOTER     4  DOLOOP      4  DOLOOPTEST   
  233.  
  234.   As you have not yet configured EDITR.BAT -- you can use the command
  235.     4  TYPE EXAMPLE2.4TH  if you want to view the definitions again
  236.  
  237. w1
  238. ~
  239. w1init
  240. 10
  241. w2
  242.     Practice printing out some strings. It can be done in IMMEDIATE
  243.  mode ( ie -- not within a word definition ) just as in BASIC.
  244.  
  245.     Take care to leave a space after the first quote mark
  246.  
  247.     " this is a test"  ."     will print correctly
  248.  
  249.     "this is a test"   ."   will give an error message
  250. w1
  251. ~
  252. w1init
  253. 10
  254. w2
  255.   Note that control characters such as LF  CR  TAB etc can be inserted
  256.  inline provided they are enclosed by up-arrow delimiters
  257.  
  258.   " this is ^9^ a test ^0dh 0ah^ to see ^13 10^ what happens " ."
  259.  
  260.     The 9 represents TAB.  CR is either 0dh ( hex ) or 13 ( decimal )
  261.                            LF is either 0ah ( hex) or 10 ( decimal)
  262.  
  263. w1
  264.  
  265. ~
  266. w2
  267. 2
  268.  Here are the definitions you've entered to date. 
  269. ddict 
  270. $
  271. ~
  272. splitscreen
  273. w2
  274. 10
  275.   Go back to the previous screen and select a word somewhere in the middle of 
  276.   those listed under USER DEFINITIONS -- then return to this screen
  277.  
  278.   Let's suppose the word you chose was HEADER
  279.  
  280.    type  4  FORGET HEADER     
  281.  
  282.   and again return to the previous screen
  283. w1
  284.   You will find that HEADER and all the words defined after it have
  285.   now been deleted from 4th_86.
  286.  
  287. $
  288. ~
  289. splitscreen
  290. w2
  291. 19
  292.   Now let's define a new word -- type in 
  293.      4  : new-word " this is a test " ." ;    
  294.  
  295.    you can make sure it works by typing  4  new-word    
  296.  
  297.    Now let's try to re-define the same word 
  298.           4  : new-word " this is not another test " ." ;    
  299.  
  300.     when you get asked if you want to redefine -- answer Y
  301.  
  302.     Now test by again typing   4  new-word   
  303.  
  304.     type  4  forget new-word   and then  4  new-word   
  305.  
  306.     you will see that the original definition has been restored
  307.  
  308. w1
  309. $
  310. ~
  311. splitscreen
  312. w2
  313. 10
  314.   by now you should be reasonably comfortable with how 4th_86 functions
  315.     ( see next screen for window manipulation commands )
  316.   repeat the last screen if unsure -- and then type
  317.  
  318.      4  w2    followed by  4 splitat 0      and 
  319.  
  320.      4  ddict    
  321. w1
  322.     Now define and redefine some words -- use DDICT to examine the
  323.  dictionary -- FORGET some words and use DDICT again.
  324.  
  325.     If you're feeling really brave, leave thhis tutorial by 
  326.  typing  4  fullscreen  N  and enjoy the freedom of a full size screen.
  327.  
  328.     Configure EDITR.BAT and ASMBL.BAT and work through the examples
  329.  in the documentation.
  330.  
  331.     You can always return to windowed mode by the words 
  332.      4  splitscreen  N  or  4  help  N  
  333. w1
  334. $
  335. ~
  336. splitscreen
  337. w2
  338. 10
  339.     W1  places cursor in upper window
  340.     W2  places cursor in lower window
  341.        W1INIT and W2INIT clear windows
  342.     SPLIT divides windows equally mid-screen
  343.     SPLITAT N divides windows at line N
  344.        ( if N > 23 it's truncated to 23 )
  345.         SPLITSCREEN is the same as SPLIT
  346.         FULLSCREEN is the same as UNSPLIT
  347.  
  348. w1
  349.  
  350.     The source code for the tutorial / windows is included
  351.     as 7TUT04.4TH
  352.  
  353.     All source code is pure ascii and can be printed as-is
  354.         or edited with any ASCII type editor.
  355.  
  356.     examine the code to get further ideas of how to use FORTH
  357.  
  358. $
  359. 
  360.